#include "stdafx.h"
#include "Display.h"
#include "platform/Device.h"
#include "render/Render.h"

using namespace unigame;

void Display::viewSize(float x, float y, float w, float h)
{
	m_viewSize.set(x, y, w, h);
	Vector2f size =	Device::currentDevice()->screenSize();
	m_viewPixel.set(x * size.x, y * size.y, w * size.x, h * size.y);
	m_isAspectChange = true;
}

void Display::viewPiexl(float x, float y, float w, float h)
{
	m_viewPixel.set(x, y, w, h);
	Vector2f size =	Device::currentDevice()->screenSize();
	m_viewSize.set(x / size.x, y / size.y, w / size.x, h / size.y);
	m_isAspectChange = true;
}

void Display::resize()
{
	if(m_isScaleFix)
	{
		viewSize(m_viewSize.x, m_viewSize.y, m_viewSize.z, m_viewSize.w);
	}
	else
	{
		viewPiexl(m_viewPixel.x, m_viewPixel.y, m_viewPixel.z, m_viewPixel.w);
		m_isAspectChange = false;
	}
}

void Display::update()
{
	m_isAspectChange = false;
}

void Display::viewPort()
{
	Render::instance()->setViewPort(m_viewPixel.x, m_viewPixel.y, m_viewPixel.z, m_viewPixel.w);
}